﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.Utilities;
using MsTestUtilities.RowTests;

namespace MsTestUtilitiesTests.Utilities
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void AssertionHoldsTests()
        {
            new TestScenarioBuilder<int[], int[], IAssertionResult>()
                .For(CollectionAsserter.AreEquivalent)
                .Given(new int[] { }, new int[] { }).Expect(AssertionResult.Success).Because("Two emtpy arrays are equivalent.")
                .Given(new int[] { 1, 2 }, new int[] { 1, 2 }).Expect(AssertionResult.Success).Because("Arrays are equal.")
                .Given(new int[] { 1, 3, 2 }, new int[] { 3, 2, 1 }).Expect(AssertionResult.Success).Because("Arrays contain same elements in different order.")
                .Given(new int[] { 1 }, new int[] { }).Expect(FailedAssertion).Because("Expected contains more elements")
                .Given(new int[] { }, new int[] { 1 }).Expect(FailedAssertion).Because("Actual contains more elements")
                .Given(new int[] { 1 }, new int[] { 2 }).Expect(FailedAssertion).Because("Elements differ")
                .Given(new int[] { 2, 2 }, new int[] { 1, 2 }).Expect(FailedAssertion).Because("Actual contains unexpected values.")
                .Given(new int[] { 1, 2 }, new int[] { 2, 2 }).Expect(FailedAssertion).Because("Actual doesn't contain all values.")
                .Evaluate();            
        }

        [TestMethod]
        public void AssertionErrorMessageTests()
        {
            new TestScenarioBuilder<int[], int[], string>()
                .For((expected, actual) => CollectionAsserter.AreEquivalent(expected, actual).AssertionError)
                .Given(new int[] { }, new int[] { }).Expect(string.Empty).Because("No error displayed when assertion holds.")                
                .Given(new int[] { 1, 2 }, new int[] { }).Expect(s => s.Contains("Missing element(s) [1, 2]")).Because("Missing elements should be listed")
                .Given(new int[] { }, new int[] { 1, 2 }).Expect(s => s.Contains("Extra element(s) [1, 2]")).Because("Extra elements should be listed")
                
                .Given(new int[] { 1, 1 }, new int[] { 1 }).Expect(s => s.Contains("Expected 2. Actual 1.")).Because("Length difference should be displayed.")
              
                .Evaluate();
        }

        private bool FailedAssertion(IAssertionResult assertionResult)
        {
            return assertionResult != AssertionResult.Success;
        }
    }
}
